<?php

/**
 * customers actions.
 *
 * @package    sf_sandbox
 * @subpackage customers
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 8507 2008-04-17 17:32:20Z fabien $
 */
class customersActions extends sfActions
{
  public function executeIndex()
  {
    $this->customersList = CustomersPeer::doSelect(new Criteria());
  }

  public function executeCreate()
  {
    $this->form = new CustomersForm();

    $this->setTemplate('edit');
  }

  public function executeEdit($request)
  {
    $this->form = new CustomersForm(CustomersPeer::retrieveByPk($request->getParameter('customers_id')));
  }

  public function executeUpdate($request)
  {
    $this->forward404Unless($request->isMethod('post'));

    $this->form = new CustomersForm(CustomersPeer::retrieveByPk($request->getParameter('customers_id')));

    $this->form->bind($request->getParameter('customers'));
    if ($this->form->isValid())
    {
      $customers = $this->form->save();

      $this->redirect('customers/edit?customers_id='.$customers->getCustomersId());
    }

    $this->setTemplate('edit');
  }

  public function executeDelete($request)
  {
    $this->forward404Unless($customers = CustomersPeer::retrieveByPk($request->getParameter('customers_id')));

    $customers->delete();

    $this->redirect('customers/index');
  }
}
